package com.evildog.workspace.life.application.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.evildog.workspace.life.application.bo.NoteTagBO;
import com.evildog.workspace.life.application.convert.NoteTagConvert;
import com.evildog.workspace.life.application.dto.NoteTagDTO;
import com.evildog.workspace.life.application.entity.NoteTag;
import com.evildog.workspace.life.application.mapper.NoteTagMapper;
import com.evildog.workspace.life.application.service.NoteTagService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

@Service
public class NoteTagServiceImpl extends ServiceImpl<NoteTagMapper, NoteTag> implements NoteTagService {


    @Override
    public NoteTagBO save(NoteTagDTO dto) {
        NoteTag newNoteTag = NoteTagConvert.INSTANCE.convert(dto);
        save(newNoteTag);
        return NoteTagConvert.INSTANCE.convert(newNoteTag);
    }

    @Override
    public boolean updateById(Long id, NoteTagDTO dto) {
        NoteTag oldNoteTag = getById(id);
        Assert.notNull(oldNoteTag, "noteTag is null!");
        NoteTag newNoteTag = NoteTagConvert.INSTANCE.convert(dto);
        newNoteTag.setId(id);
        return updateById(newNoteTag);
    }
}
